﻿// <copyright file="ConnexityNotifier.cs" company="Ecole Normale Supérieure">
// Released under GPLv2
// </copyright>
// <summary>Contains the Connexity Notifier service.</summary>

namespace Sqwarea.Batch
{
    using System;
    using Lokad.Cloud.ServiceFabric;
    using Sqwarea.GameLogic.Connexity;
    using Sqwarea.Persistence;
    using Sqwarea.Persistence.Azure;

    /// <summary>
    /// This class acts as connexity issue notifier.
    /// </summary>
    [QueueServiceSettings(
        AutoStart = true, 
        QueueName = QueueProvider.ConnexityBreakPointQueueName, 
        ProcessingTimeoutSeconds = GlobalParameters.ConnexityNotifierTimeOutSeconds)]
    public class ConnexityNotifier : QueueService<ConnexityBreakpoint>
    {
        /// <summary>
        /// Gets or sets the provider of connexity, called when there is a connexity breakpoint
        /// </summary>
        public IConnexityProvider ConnexityProvider { get; set; }

        /// <summary>
        /// This method is an entry point of the service of connexity issue notification.
        /// </summary>
        /// <param name="message">The case that may have connexity issue due to ownership change.</param>
        protected override void Start(ConnexityBreakpoint message)
        {
            this.ConnexityProvider.EnforceConnexity(message);
        }
    }
}
